# Makefile to build application for testing Network module

CC = g++
UNAME := $(shell uname)

ifeq ($(UNAME), Linux)
# Linux
LIBCHECKERS = libcheckers.so
else
ifeq ($(UNAME), Darwin)
# Mac OS X
LIBCHECKERS = libcheckers.dylib
else
# Windows
LIBCHECKERS = libcheckers.dll
endif
endif

.PHONY: all clean board checkers network server client

all: board checkers network server client

#checkers: Checkers.o $(LIBCHECKERS)

server:
	cd testserver; qmake .; make

client:
	cd testclient; qmake .; make

board:
	cd ../../board; make

checkers:
	cd ../../checkers; make

network:
	cd ../; qmake .; make

#Checkers.o:
#	$(CC) -Wall -fPIC -lboard -L../../board/ -c -g -O0 -o $@ Checkers.cpp

libcheckers.so:
	rm -f libcheckers.so.1.0.0 libcheckers.so.1.0 libcheckers.so.1 libcheckers.so
	$(CC) -shared -Wl,-soname,libcheckers.so.1 -o libcheckers.so.1.0.0 Checkers.o
	ln -s libcheckers.so.1.0.0 libcheckers.so.1.0
	ln -s libcheckers.so.1.0 libcheckers.so.1
	ln -s libcheckers.so.1 libcheckers.so

libcheckers.dylib:
	$(CC) -dynamiclib -o libcheckers.dylib Checkers.o

libcheckers.dll:
	$(CC) -shared -o libcheckers.dll Checkers.o

testserver.o:
	$(CC) -Wall -lnetwork -L../ -lcheckers -L. -I../ -c -g -O0 -o $@ testserver.cpp

testserver:
	$(CC) -o $@ testserver.o

testserver.exe:
	$(CC) -o $@ testserver.o

testclient.o:
	$(CC) -Wall -lnetwork -L../ -I../ -c -g -O0 -o $@ testclient.cpp

testclient:
	$(CC) -o $@ testserver.o

testclient.exe:
	$(CC) -o $@ testserver.o

clean:
	cd ../../board; make clean
	cd ../; make clean
	cd testserver; make clean
	cd testclient; make clean
	rm -vf *.o libcheckers*